<?php

/**
 * 自动生成 WxEventVoteStatService
 * 
 * Apps/Common/Service/WxEventVoteStatService.class.php
 * gt_admin @ 2015-09-11
 */
namespace Common\Service;


class WxEventVoteStatService {
  
  private static $instance;

  public static function instance() {
    if (self::$instance == null) {
      $instance = new WxEventVoteStatService();
    }

    return $instance;
  }
  
  function get_default_row() {
    return array(
        'id' => '' ,  
'date' => '' ,  
'play_num' => '0' ,  
'user_num' => '0' ,  

    );
  }

  function get_by_id( $id ){
    $WxEventVoteStat = M('WxEventVoteStat');
    $data = $WxEventVoteStat->find( $id ) ;
    return $data ? $data : array();
  }
  
  function get_by_cond( $config ) {
    $default = array(
        'page' => 1,
        'page_size' => 6,
        'status' => '' ,
        'count' => FALSE,
        'order' => 'DESC' ,
        'sort' => 'id',
    );

    $config = extend($config, $default);

    $WxEventVoteStat = M('WxEventVoteStat');
    
    $where = array();
    
    if ( !empty($config['status']) ) {
      $where['status'] = $config['status'] ;
    }
        
    if ($config['count']) {
      return $WxEventVoteStat->where($where)->count() ;
    } else {
      $order = $config['sort'] . ' ' . $config['order'] ;
      $limit = ($config['page'] - 1 ) * $config['page_size'] . ' , ' . $config['page_size'];
      $data = $WxEventVoteStat
              ->where($where)
              ->limit($limit)->order( $order )->select();
      //echo $WxEventVoteStat->_sql();
      return $data ? $data : array();
    }
  }
  
  function create( $data ) {
    $WxEventVoteStat = M('WxEventVoteStat');
    $ret = $WxEventVoteStat->add($data);
    if ($ret === FALSE ) {
      return ajax_arr('添加失败', FALSE);
    } else {
      return ajax_arr('添加成功', TRUE, array(
        'id' => $ret
      ));
    }
  }

  function update( $id , $data ) {
    $WxEventVoteStat = M('WxEventVoteStat');
    
    $ret = $WxEventVoteStat->where("id = %d", $id)->save($data);
    if ( $ret === FALSE ) {
      return ajax_arr('编辑失败', FALSE);
    } else {
      return ajax_arr('编辑成功', TRUE);
    }
  }
  
  function delete( $ids ) {
    $WxEventVoteStat = M('WxEventVoteStat');
    $ret = $WxEventVoteStat->delete($ids);
    if ($ret == 0) {
      return ajax_arr('未删除任何数据', FALSE);
    } else if (!$ret) {
      return ajax_arr('删除失败', FALSE);
    } else {
      return ajax_arr('删除' . $ret . '行数据', TRUE);
    }
  }
}
